/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package metier.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Adrien
 */
@Entity
@Table(name="compte")
public class Compte implements Serializable {
    private static final long serialVersionUID = 1L;
    
    public static final int COMPTE_ENABLED = 0, COMPTE_DISABLED = 1;
    
    @Id
    @SequenceGenerator(name="compte_id_seq",
                       sequenceName="compte_id_seq",
                       allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE,
                    generator="compte_id_seq")
    @Column(name = "id", updatable=false)
    private Long id;
    
    @NotNull
    @Size(max=60)
    @Column
    private String nom;
    
    @NotNull
    @Column
    private float montant;
    
    @NotNull
    @Column
    private int etat;
    
    @ManyToOne
    private Client possesseur;
    
    @OneToMany(mappedBy="debiteur",fetch=FetchType.EAGER, cascade=CascadeType.ALL)
    private List<Virement> debits;
    
    @OneToMany(mappedBy="crediteur",fetch=FetchType.EAGER, cascade=CascadeType.ALL)
    private List<Virement> credits;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public float getMontant() {
        return montant;
    }

    public void setMontant(float montant) {
        this.montant = montant;
    }

    public Client getPossesseur() {
        return possesseur;
    }

    public void setPossesseur(Client possesseur) {
        this.possesseur = possesseur;
    }

    public int getEtat() {
        return etat;
    }

    public List<Virement> getDebits() {
        return debits;
    }

    public void setDebits(List<Virement> debits) {
        this.debits = debits;
    }

    public List<Virement> getCredits() {
        return credits;
    }

    public void setCredits(List<Virement> credits) {
        this.credits = credits;
    }

    public void setEtat(int etat) {
        this.etat = etat;
    }
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compte)) {
            return false;
        }
        Compte other = (Compte) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "metier.entity.Compte[ id=" + id + " ]";
    }
    
}
